package com.lehecai.core.api.openapi;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class OpenAPIPush extends AbstractApiResultBean {

    public static final String QUERY_PUSH_ID = "id";
    public static final String QUERY_PUSH_TITLE = "title";
    public static final String QUERY_PUSH_STATUS = "status";
    public static final String QUERY_PUSH_APP_TYPE = "app_type";
    public static final String QUERY_PUSH_TIME_ADD = "time_add";

    public static final String SET_PUSH_TITLE = "title";
    public static final String SET_PUSH_CONTENT = "content";
    public static final String SET_PUSH_STATUS = "status";
    public static final String SET_PUSH_NEWS_ID = "news_id";
    public static final String SET_PUSH_APP_TYPE = "app_type";
    public static final String SET_PUSH_APP_VERSION = "app_version";
    public static final String SET_PUSH_SOURCE = "source";
    public static final String SET_PUSH_TIME = "push_time";
    public static final String SET_PUSH_URL = "url";

    public static final String ORDER_PUSH_ID = "id";
    public static final String ORDER_PUSH_TIME_ADD = "time_add";

    private String id;						//编号
    private String title;					//标题
    private String content;					//push内容
    private YesNoStatus status;				//状态
    private Date addTime;					//添加的时间
    private String newsId;					//对应活动id
    private OpenAPIAppType appType;			//平台类型
    private String appVersion;				//版本号
    private String source;					//渠道
    private Date pushTime;					//推送的时间
    private String url;						//push所对应的链接

    public static OpenAPIPush convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        OpenAPIPush openAPIPush = new OpenAPIPush();

        openAPIPush.setId(getString(object, "id"));
        openAPIPush.setTitle(getString(object, "title"));
        openAPIPush.setContent(getString(object, "content"));
        openAPIPush.setStatus(YesNoStatus.getItem(getInt(object, "status")));
        openAPIPush.setAddTime(CoreDateUtils.parseDate(getString(object, "time_add"), CoreDateUtils.DATETIME));
        openAPIPush.setNewsId(getString(object, "news_id"));
        openAPIPush.setAppType(OpenAPIAppType.getItem(getInt(object, "app_type")));
        openAPIPush.setAppVersion(getString(object, "app_version"));
        openAPIPush.setSource(getString(object, "source"));
        openAPIPush.setPushTime(CoreDateUtils.parseDate(getString(object, "push_time"), CoreDateUtils.DATETIME));
        openAPIPush.setUrl(getString(object, "url"));

        return openAPIPush;
    }

    public static List<OpenAPIPush> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<OpenAPIPush> list = new ArrayList<OpenAPIPush>();
        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public YesNoStatus getStatus() {
        return status;
    }

    public void setStatus(YesNoStatus status) {
        this.status = status;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public String getNewsId() {
        return newsId;
    }

    public void setNewsId(String newsId) {
        this.newsId = newsId;
    }

    public OpenAPIAppType getAppType() {
        return appType;
    }

    public void setAppType(OpenAPIAppType appType) {
        this.appType = appType;
    }

    public String getAppVersion() {
        return appVersion;
    }

    public void setAppVersion(String appVersion) {
        this.appVersion = appVersion;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public Date getPushTime() {
        return pushTime;
    }

    public void setPushTime(Date pushTime) {
        this.pushTime = pushTime;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
}
